package com.obao.business.action;

import java.io.File;
import java.io.IOException;
import java.util.*;


import com.obao.business.entity.*;
import com.obao.user.entity.Banner;

import com.obao.business.service.IProductService;
import com.obao.user.entity.Collect;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by Administrator on 2016/11/8.
 */
public class ProductAction extends ActionSupport {
    private IProductService productService;
    private List<Product> productList = null;
    private List<ProductSort> productSorts=null;
    private List<Business> businesss=null;
    private Product product;
    private Business business;
    private ProductSort productSort;
	private List<Banner> banners;
    private String msg;
	private File userPic;
	private String userPicFileName;
	private String userPicContentType;
	private Integer start; //分页开始
	private Integer end;
	private Integer num;//热门商品查询数量
	private Integer id;
	private Integer userId;
	private Object productDetail;
	private Map<String ,Object> data = new HashMap<String, Object>();
	private List<BusinessDomain> domains;


	/**
	 * 商品详情
	 */
	public String detail(){
		productDetail = productService.findDetailByid(id);
		List<ProductFlavor> flavors =  productService.findFlavor(id);
		List<ProductSize> sizes = productService.findSize(id);
		Business business = productService.findBusinessId(id);
		Integer collect= productService.isCollect(id,userId);
		data.put("isCollect",collect);
		data.put("business",business);
		data.put("sizes", sizes);
		data.put("flavors",flavors);
		data.put("detail", productDetail);
		return "data";
	}
	/**
	 * 模糊查询商品列表
	 * @return
	 */
	public String searchList(){
		productList = productService.searchProductList(msg);
		return "productList";
	}

	/**
	 * 查找促销商品列表
	 */
	public String promotionProducts() {
		productList = productService.findProtions();
		return "productList";
	}
	/**
	 * 热门商品查询列表
	 */
	public String hotProducts() {
		productList = productService.findHotProducts(num);
		return "productList";
	}
	/**
	 * banner图查询列表
	 */
	public String banners() {
		banners = productService.findBanners();
		return "banners";
	}
	/**
	 * 区域列表
	 */
	public String domains() {
		domains = productService.findDomains();
		return "domains";
	}
    /**
     * 添加商品
     * @return
     */
    public String add(){
			for(int i = 0 ; i < 50; ++i) {
				Product product = new Product();
				product.setState(0);
				product.setProductName("哈哈"+i);
				product.setPromotion(1);
				product.setNewPrice(i*10);
				product.setAddTime(new Date());
				product.setSales(0);
				product.setRemark("free");
				productService.save(product);
			}
			msg = "添加成功";
//		}
		return "addSuccess";
	}




    public Business getBusiness() {
		return business;
	}
	public void setBusiness(Business business) {
		this.business = business;
	}
	/**
     * get and set...
     */
    public void setProductService(IProductService productService) {
        this.productService = productService;
    }

    public List<ProductSort> getProductSorts() {
		return productSorts;
	}

	public void setProductSorts(List<ProductSort> productSorts) {
		this.productSorts = productSorts;
	}

	public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public ProductSort getProductSort() {
		return productSort;
	}
	public void setProductSort(ProductSort productSort) {
		this.productSort = productSort;
	}
	public List<Product> getProductList() {
        return productList;
    }

    public List<Business> getBusinesss() {
		return businesss;
	}
	public void setBusinesss(List<Business> businesss) {
		this.businesss = businesss;
	}
	public void setProductList(List<Product> productList) {
        this.productList = productList;
    }
	public void setUserPic(File userPic) {
		this.userPic = userPic;
	}

	public void setUserPicFileName(String userPicFileName) {
		this.userPicFileName = userPicFileName;
	}

	public void setUserPicContentType(String userPicContentType) {
		this.userPicContentType = userPicContentType;
	}

	public File getUserPic() {

		return userPic;
	}

	public String getUserPicFileName() {
		return userPicFileName;
	}

	public String getUserPicContentType() {
		return userPicContentType;
	}

	public IProductService getProductService() {
		return productService;
	}

	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public void setEnd(Integer end) {
		this.end = end;
	}

	public Integer getEnd() {
		return end;
	}

	public void setNum(Integer num) {
		this.num = num;
	}

	public Integer getNum() {
		return num;
	}

	public void setBanners(List<Banner> banners) {
		this.banners = banners;
	}

	public List<Banner> getBanners() {

		return banners;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {

		return id;
	}

	public void setProductDetail(Object productDetail) {
		this.productDetail = productDetail;
	}

	public Object getProductDetail() {
		return productDetail;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	public Map<String, Object> getData() {

		return data;
	}

	public List<BusinessDomain> getDomains() {
		return domains;
	}

	public void setDomains(List<BusinessDomain> domains) {
		this.domains = domains;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}
}
